import { reactive } from "vue";
import type { FormRules } from "element-plus";
import { isPhone, isEmail } from "@pureadmin/utils";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  department_belong: [{ required: true, message: "部门为必选项", trigger: ["blur", "change"] }],
  position: [{ required: true, message: "职位为必选项", trigger: ["blur", "change"] }],
  role: [{ required: true, message: "角色为必选项", trigger: ["blur", "change"] }],
  nickname: [{ required: true, message: "昵称为必填项", trigger: "blur" }],
  account: [{ required: true, message: "用户名为必填项", trigger: "blur" }],
  password: [{ required: true, message: "用户密码为必填项", trigger: "blur" }],
  phone: [{ required: true, message: "手机号为必填项", trigger: "blur" }, {
    validator: (rule, value, callback) => {
      if (!isPhone(value)) {
        callback(new Error("请输入正确的手机号码格式"));
      } else {
        callback();
      }
    },
    trigger: "blur"
  }],
  // email: [
  //   {
  //     validator: (rule, value, callback) => {
  //       if (value === "") {
  //         callback();
  //       } else if (!isEmail(value)) {
  //         callback(new Error("请输入正确的邮箱格式"));
  //       } else {
  //         callback();
  //       }
  //     },
  //     trigger: "blur"
  //   }
  // ]
});
